package com.cainiao.controller;

import com.cainiao.pojo.Result;
import com.cainiao.pojo.Student;
import com.cainiao.pojo.StudentQueryParam;
import com.cainiao.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){
        return Result.success(studentService.findStudent(studentQueryParam));
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Long> ids){
        studentService.delete(ids);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Student student){
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(studentService.findById(id));
    }

    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result updateViolation(@PathVariable Integer id,@PathVariable Integer score){
        studentService.updateViolation(id,score);
        return Result.success();
    }

}
